#include "game.h"
using namespace std;
int f[201][201];
vector<int> g[201];
vector<int> adj[201];
int siz[201];
bool vis[201];
vector<int> guess(int n,int limit){
    vector<int> ans(n);
    for(int i=1;i<=n;i++)ans[i-1]=0;
    vector<int> que(n);
    for(int i=1;i<=n;i++)que[i-1]=i;
    int res=count(que);
    if(res==n)return que;
    for(int i=1;i<=n;i++){
        f[i][i]=res;
        for(int j=i+1;j<=n;j++){
            swap(que[i-1],que[j-1]);
            f[i][j]=f[j][i]=count(que);
            swap(que[i-1],que[j-1]);
        }
    }
    for(int i=1;i<=n;i++){
        if(ans[i-1])continue;
        int mx=-1,ps=0;
        for(int j=1;j<=n;j++)
            if(f[i][j]>mx)mx=f[i][j],ps=j;
        if(mx<=res){
            ans[i-1]=i;
            continue;
        }
        if(mx>res+1){
            ans[i-1]=ps;
            ans[ps-1]=i;
            continue;
        }
        for(int j=1;j<=n;j++)if(f[i][j]==res+1)g[i].push_back(j);
    }
    for(int i=1;i<=n;i++){
        if(ans[i-1]>0||vis[i])continue;
        adj[i].push_back(i);
        siz[i]++;
        vis[i]=1;
        int j=g[i][0],k=i;
        while(j!=i){
            adj[i].push_back(j);
            siz[i]++;
            vis[j]=1;
            int l=g[j][0]+g[j][1]-k;
            k=j;
            j=l;
        }
        adj[i].push_back(i);
        for(int j=0;j<siz[i];j++)ans[adj[i][j]-1]=adj[i][j+1];
    }
    res=count(ans);
    if(res==n)return ans;
    for(int i=1;i<=n;i++){
        if(!siz[i])continue;
        que=ans;
        for(int j=siz[i];j>0;j--)que[adj[i][j]-1]=adj[i][j-1];
        int cnt=count(que);
        if(cnt>res)res=cnt,ans=que;
        if(res==n)return ans;
    }
    return ans;
}
